Skip to content

construct-cli: severity-tagged diagnostics — CLI Standard v1.1.0 compliance - #36

Merged
UnbreakableMJ merged 1 commit into
mainfrom
feat/construct-diagnostics
Aug 9, 2026
Merged

construct-cli: severity-tagged diagnostics — CLI Standard v1.1.0 compliance#36
UnbreakableMJ merged 1 commit into
mainfrom
feat/construct-diagnostics

Conversation

@UnbreakableMJ

Copy link
Copy Markdown
Contributor

What

Brings construct-cli into compliance with the diagnostics spec added in #35 (CLI Standard v1.1.0, references/diagnostics.md) — the reference implementation of severity-tagged, dual-audience error/feedback messages.

New src/output/diagnostic.rs

  • Severity ladder (Info < Ok < Warn < Error) with the §18.2.1 tags [INFO]/[OK]/[WARN]/[ERROR].
  • Diagnostic type: machine mode emits a single-line {"diagnostic":{severity, code, message, hint?, timestamp, command, …}} envelope on stderr; human mode renders [TAG] message + indented hint:, colored via theme tokens with the tag surviving colorless output.
  • Severity floor on Context: --quiet → errors only; agent env (AI_AGENT/AGENT) → warn+; default → ok+; --verboseinfo+. Errors (AppError) never consult the floor.

Fixes

  • TUI fallback: warn_tui_fallback used to print raw JSON unconditionally — even on a human TTY — in the deprecated {"warning":{…}} shape with a non-spec fell_back_to field and no hint. Now mode::resolve returns the fallback reason and main emits a proper TUI_FALLBACK warn diagnostic (specific reason in the reason extension, runnable construct skill find --json hint), honoring mode and floor.
  • FORCE_COLOR precedence: the chain checked NO_COLOR first, so FORCE_COLOR could never override it — contradicting both its own comment and the spec. Reordered (matches force-color.org and CLI Standard v1.1.0 — diagnostic severity ladder, machine envelope, unified rendering #35's §6 fix); extracted as a pure color_env_decision with table tests.
  • Human error render: error:/indented hint: → the unified [ERROR] + hint: layout; the colorless branch now carries the tag too (§18.2.1: color is never the sole carrier of meaning).
  • Paste-test hints: ship's oversized-description hint ($EDITOR … # trim…) → python3 .githooks/check-description-length.py <skill>/SKILL.md; the TUI error hint's inline comment removed.
  • sync nix passthrough gated by the info floor instead of a bare ctx.verbose check.

Theme migration (§11.1)

theme.rs moves from the grandfathered v1.33 six-token palette (which had no warning color distinct from error) to the eleven Steelbore 2 role tokens — this release is the "next minor release" the grandfathering clause named. render.rs and the TUI remapped per tui-explore.md §3 (labels/borders → structure, values → foreground, marks/selection → success, active/attention → accent).

Sample output

$ AI_AGENT=claude-code_2-1-218_agent construct --format explore
{"diagnostic":{"severity":"warn","code":"TUI_FALLBACK","message":"interactive explore mode unavailable; falling back to `--format json`","hint":"construct skill find --json","timestamp":"2026-08-09T23:14:00Z","command":"construct --format explore","reason":"agent environment (AI_AGENT/AGENT) is set"}}

$ construct skill sync --flake-dir /no/such   # human TTY
[ERROR] flake directory `/no/such` does not exist
  hint: construct skill sync --flake-dir <existing-dir>

Verification

cargo test (56 tests, including new floor-table, envelope-shape, tag-survival, FORCE_COLOR-override, agent-env-fallback, and quiet-suppression tests), cargo clippy --all-targets -- -D warnings, cargo fmt --check — all green locally. Manual smoke of the error path and explore fallback under piped/agent/quiet conditions matches the spec.

Sequencing note: independent of #35 at the code level, but reviews best after it — the spec sections cited here are introduced there.

🤖 Generated with Claude Code

Implements the diagnostics spec (references/diagnostics.md, PR #35):

- New output/diagnostic.rs: Severity ladder (Info < Ok < Warn < Error,
  §18.2.1 tags), Diagnostic type emitting single-line
  {"diagnostic":{...}} envelopes in machine mode and [TAG]-first human
  rendering, gated by the severity floor on Context (--quiet → errors
  only, agent env → warn+, default → ok+, --verbose → info+). Errors
  (AppError) never consult the floor.
- error.rs human render: error:/hint: → [ERROR] tag + indented hint:,
  tag carried in the colorless branch too (color is never the sole
  carrier of meaning).
- mode.rs: warn_tui_fallback deleted — resolve() now returns the
  fallback reason and main emits a TUI_FALLBACK warn diagnostic after
  Context exists (no more raw JSON on a human TTY; drops the non-spec
  fell_back_to field). FORCE_COLOR now checked before NO_COLOR so it
  overrides it (was inverted vs its own comment and the spec).
- theme.rs migrated from the grandfathered v1.33 six-token palette to
  the eleven Steelbore 2 §11.1 role tokens (this is the "next minor
  release" the grandfathering clause named); render.rs and tui/mod.rs
  remapped per tui-explore.md §3.
- sync.rs nix progress passthrough gated by the info floor;
  ship.rs oversized-description hint and tui/mod.rs fallback hint made
  paste-test-clean runnable commands.
- Tests: floor table, envelope shape/single-line/hint-omission, tag
  presence with and without color, FORCE_COLOR-over-NO_COLOR, agent-env
  explore fallback parses as a warn diagnostic, --quiet suppresses the
  fallback but never errors.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac79d7c8ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

5,
format!("SKILL.md description exceeds the {DESCRIPTION_CAP}-character cap: {detail}"),
format!("$EDITOR {first}/SKILL.md # trim the `description` frontmatter field"),
format!("python3 .githooks/check-description-length.py {first}/SKILL.md"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make the description-cap hint use the selected repo

When construct skill ship --repo /path/to/clone is invoked from outside that clone—a supported use case—this hint searches the caller's current directory for both .githooks/check-description-length.py and the skill, so pasting it fails instead of providing the promised runnable recovery command. Build both paths from repo (and quote them safely) so the hint works independently of the invocation directory.

AGENTS.md reference: construct-cli/AGENTS.md:L57-L60

Useful? React with 👍 / 👎.

@UnbreakableMJ
UnbreakableMJ merged commit 97a70d8 into main Aug 9, 2026
3 checks passed
@UnbreakableMJ
UnbreakableMJ deleted the feat/construct-diagnostics branch August 9, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant